package com.gufe.controller.admin.mmp;

import com.gufe.dto.SwiperDTO;
import com.gufe.service.admin.mmp.SwiperService;
import com.gufe.result.Result;
import com.gufe.vo.SwiperVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/mp")
/*管理端小程序轮播图*/
public class SwiperController {

    @Autowired
    SwiperService swiperService;

    /*获取所有的首页轮播图及描述信息*/
    @GetMapping("/indexImg")
    @Cacheable(cacheNames = "swiperCache",key = "'getAllIndexImg'")
    public Result<List<SwiperVO>> getAllIndexImg(){
        log.info("查询首页所有轮播图！");
        return Result.success(swiperService.getAllIndexImg());
    }

    /*根据id查询轮播图及描述信息*/
    @GetMapping("/indexImg/{id}")
    @CacheEvict(cacheNames = "swiperCache",key = "'getAllIndexImg'") // 清除所有轮播图缓存
    public Result<SwiperVO> getIndexImgById(@PathVariable Integer id){
        log.info("查询首页id:{}轮播图！",id);
        return Result.success(swiperService.getIndexImgById(id));
    }

    /*根据id修改轮播图信息*/
    @PutMapping("/indexImg")
    @CacheEvict(cacheNames = "swiperCache",key = "'getAllIndexImg'") // 清除所有轮播图缓存
    public Result<String> updateIndexImg(@RequestBody SwiperDTO swiperDTO){
        log.info("修改首页轮播图信息：{}！", swiperDTO);
        swiperService.updateIndexImg(swiperDTO);
        return Result.success();
    }

    /*获取所有预征班轮播图及描述信息*/
    @GetMapping("/ppt-swiper")
    @Cacheable(cacheNames = "swiperCache",key = "'getAllPPTSwiper'")
    public Result getAllPPTSwiper(){
        log.info("查询预征班所有轮播图！");
        List<SwiperVO> swipers= swiperService.getAllPPTSwiper();
        return Result.success(swipers);
    }

    /*根据id查询轮播图及描述信息*/
    @GetMapping("/ppt-swiper/{id}")
    @CacheEvict(cacheNames = "swiperCache",key = "'getAllPPTSwiper'") // 清除所有轮播图缓存
    public Result getPPTSwiperById(@PathVariable Integer id){
        log.info("查询预征班id:{}轮播图！",id);
        SwiperVO swiper = swiperService.getPPTSwiperById(id);
        return Result.success(swiper);
    }

    /*根据id修改轮播图信息*/
    @PutMapping("/ppt-swiper")
    @CacheEvict(cacheNames = "swiperCache",key = "'getAllPPTSwiper'") // 清除所有轮播图缓存
    public Result updatePPTSwiper(@RequestBody SwiperDTO swiperDTO){
        log.info("修改预征班轮播图信息：{}！", swiperDTO);
        swiperService.updatePPTSwiper(swiperDTO);
        return Result.success();
    }





}
